/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Globalization;
using DaveSexton.DocProject.MSHelpCompiler;

namespace DaveSexton.DocProject.Sandcastle
{
	[Serializable]
	public sealed class Help2CompilerLoader : AssemblyLoader
	{
		#region Public Properties
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static readonly Help2CompilerLoader Instance = new Help2CompilerLoader();
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="Help2CompilerLoader" /> class.
		/// </summary>
		private Help2CompilerLoader()
		{
		}
		#endregion

		#region Methods
		protected override System.Reflection.AssemblyName CreateAssemblyName()
		{
      return null;
		}

    protected override bool LoadAssembly(AssemblyName name)
    {
      try
      {
        return LoadAssembly();
      }
      catch (System.Runtime.InteropServices.COMException ex)
      {
        Log.Exception(ex, Resources.Errors.Help2CompilerLoadError);
      }
      catch (InvalidCastException) { }
      catch (TypeLoadException) { }

      return false;
    }

    private static bool LoadAssembly()
    {
      // Allow the framework to load the COM object by instantiating an external type
      HxComp temp = (HxComp) new HxCompClass();
      return temp != null;
    }
		#endregion
	}
}
